//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//********************************************************* 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Microsoft.TridentWordAddIn.Common
{
    public class AppendixResult
    {
        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="InsertIntoDocumentData"/> class.
        /// </summary>
        /// <param name="associationName">Name of the association.</param>
        /// <param name="comment">The comment.</param>
        public AppendixResult(string associationName, string comment, OutputType outPutType, bool isOrginal)
        {
            this.AssociationName = associationName;
            this.Comment = comment;
            this.OutPutType = outPutType;
            this.IsOrginal = isOrginal;
            this.ResultFilePaths = new List<string>();
            this.RequiredInputParameters = new List<AppendixParameter>();
            this.RequiredOutputParameters = new List<AppendixParameter>();
        }

        #endregion

        /// <summary>
        /// Gets or sets the comment.
        /// </summary>
        /// <value>The comment.</value>
        public string Comment { get; set; }

        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        /// <value>The title.</value>
        public string AssociationName { get; set; }

        /// <summary>
        /// Gets or sets the result file paths.
        /// </summary>
        /// <value>The result file paths.</value>
        public IList<string> ResultFilePaths { get; set; }

        /// <summary>
        /// Gets or sets the required input parameters.
        /// </summary>
        /// <value>The required input parameters.</value>
        public IList<AppendixParameter> RequiredInputParameters { get; set; }

        /// <summary>
        /// Gets or sets the required output parameters.
        /// </summary>
        /// <value>The required output parameters.</value>
        public IList<AppendixParameter> RequiredOutputParameters { get; set; }

        /// <summary>
        /// Gets or sets the type of the out put.
        /// </summary>
        /// <value>The type of the out put.</value>
        public OutputType OutPutType
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is orginal.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is orginal; otherwise, <c>false</c>.
        /// </value>
        public bool IsOrginal
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is image.
        /// </summary>
        /// <value><c>true</c> if this instance is image; otherwise, <c>false</c>.</value>
        public bool IsImage { get; set; }

        /// <summary>
        /// Gets or sets the schedule by.
        /// </summary>
        /// <value>The schedule by.</value>
        public string ScheduledBy { get; set; }
    }

    public class DistinctParameterName : IEqualityComparer<AppendixParameter>
    {
        /// <summary>
        /// Determines whether the specified objects are equal.
        /// </summary>
        /// <param name="x">The first object of type <paramref name="T"/> to compare.</param>
        /// <param name="y">The second object of type <paramref name="T"/> to compare.</param>
        /// <returns>
        /// true if the specified objects are equal; otherwise, false.
        /// </returns>
        public bool Equals(AppendixParameter x, AppendixParameter y)
        {
            return x.Name.Equals(y.Name);
        }

        /// <summary>
        /// Returns a hash code for the specified object.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> for which a hash code is to be returned.</param>
        /// <returns>A hash code for the specified object.</returns>
        /// <exception cref="T:System.ArgumentNullException">The type of <paramref name="obj"/> is a reference type and <paramref name="obj"/> is null.</exception>
        public int GetHashCode(AppendixParameter obj)
        {
            return obj.Name.GetHashCode();
        }
    }

    public static class InputParametersExtension
    {
        /// <summary>
        /// Distincts the specified input parameters.
        /// </summary>
        /// <param name="inputParameters">The input parameters.</param>
        /// <returns></returns>
        public static IList<AppendixParameter> Distinct(this IList<AppendixParameter> inputParameters)
        {
            var x = (from t in inputParameters
                     where !t.Value.ToString().IsNullOrEmpty()
                     select t)
                      .Distinct(new DistinctParameterName());
            return x.ToList();
        }
    }
}
